//
//  ListPeopleCollectionViewCell.m
//  markmap
//
//  Created by 甘世清 on 2024/6/30.
//

#import "ListPeopleCollectionViewCell.h"

@implementation ListPeopleCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.masksToBounds = YES;
        [self SQ_UIViewForSelfView];
    }
    return self;
}
/// 添加ui
-(void)SQ_UIViewForSelfView
{
    self.contentView.backgroundColor = SQColor(@"#303030");
    self.contentView.layer.cornerRadius = 8;
    self.contentView.clipsToBounds = YES;
    self.contentView.layer.masksToBounds = YES;
    self.bgImage = [[UIImageView alloc]init];
    self.bgImage.layer.cornerRadius = 0;
    self.bgImage.clipsToBounds = YES;
    self.bgImage.layer.masksToBounds = YES;
    self.bgImage.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:self.bgImage];
    [self.bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.contentView);
        make.height.mas_equalTo(230);
    }];
    
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(8);
            make.top.equalTo(self.bgImage.mas_bottom).offset(8);
    }];
    [self.contentView addSubview:self.sexImage];
    [self.sexImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(16);
        make.bottom.equalTo(self.nameLabel.mas_bottom);
        make.left.equalTo(self.nameLabel.mas_right).offset(6);
    }];
    [self.contentView addSubview:self.rzImage];
    [self.rzImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(16);
        make.bottom.equalTo(self.nameLabel.mas_bottom);
        make.left.equalTo(self.sexImage.mas_right).offset(6);
    }];
    [self.contentView addSubview:self.cityLabel];
    [self.cityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nameLabel);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.left.equalTo(self.contentView).offset(100);
    }];
    
    [self.contentView addSubview:self.messageLabel];
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(8);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-6);
            make.top.equalTo(self.nameLabel.mas_bottom).offset(6);
    }];
    
    [self.contentView addSubview:self.juliLabel];
    [self.juliLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(12);
            make.right.equalTo(self.contentView.mas_right).offset(-12);
            make.width.mas_equalTo(80);
            make.height.mas_equalTo(26);
    }];
    
}
- (void)setModel:(PeopleDetaileModel *)model{
    _model = model;
    self.nameLabel.text = model.name;
    self.messageLabel.text = SQNSLocalString(@"这家伙很懒,什么也没留下");
    if ([model.remark isNotEmpty]) {
        self.messageLabel.text = model.remark;
    }
    [self.bgImage sd_setImageWithURL:SQURLImage(model.portrait) placeholderImage:SQGetImage(@"zanwutouxiang")];
    if (model.gender ==1) {
        self.sexImage.image = SQGetImage(@"男");
    } else {
        self.sexImage.image = SQGetImage(@"女");
    }
    if ([self.model.city isNotEmpty]) {
        self.cityLabel.text = self.model.city;
    }
    if (model.realStatus == 2) {
        self.rzImage.image = SQGetImage(@"认证");
    } else {
        self.rzImage.image = SQGetImage(@"未认证");
    }
    if (model.distance>0) {
        self.juliLabel.hidden = NO;
        if (model.distance <1000) {
            self.juliLabel.text = [NSString stringWithFormat:@"%dm",model.distance ];
        } else  {
            self.juliLabel.text = [NSString stringWithFormat:@"%.2fkm",model.distance/1000.f];
//        } else     {
//            self.juliLabel.text = [NSString stringWithFormat:@"%.2fkkm",model.distance/1000000.f];
        }
   
    } else {
        self.juliLabel.hidden = YES;
    }

}

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT_MEDIUM(14);
        _nameLabel.textColor = UIColor.whiteColor;
        _nameLabel.backgroundColor = UIColor.clearColor;
        _nameLabel.numberOfLines = 0;
    }
    return _nameLabel;
}

- (UILabel *)messageLabel{
    if (!_messageLabel) {
        _messageLabel = [[UILabel alloc]init];
        _messageLabel.font = FONT_REGULAR(11);
        _messageLabel.textColor = SQColor(@"#BBBBBB");
        _messageLabel.backgroundColor = UIColor.clearColor;
        _messageLabel.numberOfLines = 0;
    }
    return _messageLabel;
}
- (UIImageView *)rzImage{
    if (!_rzImage) {
        _rzImage = [[UIImageView alloc]init];
        _rzImage.image = SQGetImage(@"已认证");
        _rzImage.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _rzImage;
}
- (UIImageView *)sexImage{
    if (!_sexImage) {
        _sexImage = [[UIImageView alloc]init];
        _sexImage.image = SQGetImage(@"男");
        _sexImage.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _sexImage;
}
- (UILabel *)cityLabel{
    if (!_cityLabel) {
        _cityLabel = [[UILabel alloc]init];
        _cityLabel.textColor = UIColor.whiteColor;
        _cityLabel.font = FONT_REGULAR(11);
        _cityLabel.textAlignment = NSTextAlignmentRight;
    }
    return _cityLabel;
}
- (SQCustomButton *)juliLabel{
    if (!_juliLabel) {
        _juliLabel = [[SQCustomButton alloc]initType:SQCustomButtonLeftImageType imageSize:CGSizeMake(12, 16) midmargin:4];
        _juliLabel.image = SQGetImage(@"白色定位");
        _juliLabel.SQBackimageView.image = SQGetImage(@"julibg");
        _juliLabel.titleLabel.adjustsFontSizeToFitWidth = YES;
        _juliLabel.font = FONT_MEDIUM(10);
        _juliLabel.textColor = UIColor.whiteColor;
    }
    return _juliLabel;
}
@end
